package com.zhang.filter;

import com.zhang.pojo.UserBean;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 送货员过滤器
 */
public class SendFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;

        //从session中得到登录用户信息
        UserBean user = (UserBean) req.getSession().getAttribute("user");
        if (user == null){
            resp.sendRedirect("/html/login.html?errorInfo=login");
        }else if (user.getGrade().equals("送货员")){
            filterChain.doFilter(req,resp);
        }else {
            resp.sendRedirect("/html/login.html?errorInfo='no");
        }

    }
}
